/*
 * trader.h
 *
 *  Created on: 26/mag/2014
 *      Author: PegorarS
 */

#ifndef TRADER_H_
#define TRADER_H_

#include "stockexchange.h"
#include "order.h"
#include "portfolio.h"
#include "tradertype.h"
#include "patterns.h"
#include "stock.h"
#include "neuralnetwork.h"
#include "brain.h"

namespace NS_TRADER{

	using namespace NS_NN;
	using namespace NS_STOCKEXCHANGE;

	class StudyingSession{
	public:
		StudyingSession(Ticker _stockName = NULL){
			Init(_stockName);
		}
		~StudyingSession(){}

		void Init(Ticker _stockName){
			nDataCnt = 0;
			stockName = _stockName;
		}

		int nDataCnt;
		Ticker stockName;
		StockData lastStockData;
	};

	typedef enum{
		AGE_CHILD,
		AGE_ADULT
	}AGE_STATE;

	class Trader : public SubscriberStockExchangeI, public Subscriber<Strategy>{
	public:
		Trader(NeuralNetworkMap *nnMap);
		virtual ~Trader();
		virtual void Begin(Ticker stockSeriesName);
		virtual void Update(StockData &stockData);
		virtual void Update(Strategy &forecast);

		void CorrectStrategy(const Order *pOrderCorrected);
		NeuralNetworkMap *GetGeneticMap() const;
		Portfolio *GetPortfolio();

	protected:
		void GrowUp();

		Portfolio m_portfolio;
		Brain m_brain;
		int m_age;	//eta' [giorni]
		AGE_STATE ageState;

		PublisherStockExchangeI *m_pBroker;
		StudyingSession m_currentSession;
	};
}

#endif /* TRADER_H_ */
